home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / program / dxt135.zip / DXT.CB < prev    next >
Text File  |  1996-08-03  |  44KB  |  1,262 lines

  1. /*****************************************************************************/
  2. /*
  3.     DXT.CB - BRIEF MACRO FUNCTIONS FOR
  4.  
  5.         DFTN (TM) DBASE FUNCTION TREE NAVIGATOR
  6.  
  7.     Copyright (C) Juergen Mueller (J.M.) 1992-1996
  8.     All rights reserved.
  9.  
  10.     You are expressly prohibited from selling this software in any form,
  11.     distributing it with another product, or removing this notice.
  12.  
  13.     Limited permission is given to registered DXT users to modify this
  14.     file for their own personal use only. This file may not be used for any
  15.     purpose other than in conjunction with the DXT software package.
  16.  
  17.     THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
  18.     EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, THE
  19.     IMPLIED WARRANTIES OF MERCHANTIBILITY OR FITNESS FOR A PARTICULAR
  20.     PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
  21.     PROGRAM AND DOCUMENTATION IS WITH YOU.
  22.  
  23.     written by: Juergen Mueller, Aldingerstrasse 22, D-70806 Kornwestheim,
  24.                 GERMANY
  25.  
  26.     FILE       : DXT.CB
  27.     REVISION   : 27-Apr-1996
  28.                  18:30:41
  29.  */
  30. /*****************************************************************************/
  31.  
  32. #include "dialog.h"     /* include file from original BRIEF DIALOG menus */
  33.  
  34.  
  35. /*****************************************************************************/
  36. /* defines */
  37. /*****************************************************************************/
  38. #define TMPFILE         "DXTFILE.TMP"
  39.  
  40. #define DFTNPROG        "dftn"          /* or "dftn4os2" for OS/2 */
  41.                                         /* or "dftn32" for Windows NT / Windows 95 */
  42.  
  43. #ifdef __OS2__
  44. #define upper(x)        (x)
  45. #endif
  46.  
  47. /*****************************************************************************/
  48. /**** USER macro function prototypes ****/
  49. /*****************************************************************************/
  50. void    dft(void);
  51. void    dftfind(void);
  52. void    dftmenu(void);
  53. void    dftbase(void);
  54. void    dftfilemenu(void);
  55. void    dftxrefmenu(void);
  56. void    dftxrefmenuagain(void);
  57. void    dftdefmenu(void);
  58.  
  59. /*****************************************************************************/
  60. /**** INTERNAL macro function prototypes ****/
  61. /*****************************************************************************/
  62. void    _init(void);            /* initialisation function, called on entry */
  63. void    _dxtmenu_exit(void);
  64. void    _exec_error(int retval, string format, string par1, string par2);
  65. string  _extract_item(void);
  66. void    _dxt(string, string);
  67. void    _dxt_search(string, string, string, int, int);
  68. void    _dxt_edit_file(void);
  69. void    _dxt_locate(void);
  70. void    _dxt_buffers(void);
  71. void    _dxtmenu(string, string);
  72. int     _dft_action(int, ...);
  73. void    _dxtfilemenu(string, string);
  74. int     _dxt_fileaction(int, ...);
  75. void    _dxtxrefmenu(string, string, int);
  76. int     _dxt_xrefaction(int, ...);
  77. void    _dxtdefmenu(string, string);
  78. int     _dxt_defaction(int, ...);
  79. void    _dxt_insert_sorted(string, int, int);
  80.  
  81.  
  82. /*****************************************************************************/
  83. /**** global variables ****/
  84. /*****************************************************************************/
  85. string  dft_base;               /* data base name for dft */
  86.  
  87. string  dxt_loc;                /* resulting file with item location */
  88.  
  89. string  dxt_item;               /* item to search for */
  90. int     dxt_id;                 /* item id */
  91.  
  92. string  dxt_file;               /* target file name */
  93. int     dxt_line;               /* target line, used by registered macro */
  94.  
  95. string  dft_loc;                /* resulting file for menu */
  96. int     dft_menuwidth;          /* horizontal dft menu width */
  97.  
  98. string  dft_files;              /* resulting file for filemenu */
  99. int     dft_filemenuwidth;      /* horizontal dft filemenu width */
  100.  
  101. string  dft_xref;                
  102. string  dft_xref_item;
  103. int     dft_xrefmenuwidth;       
  104.  
  105. string  dft_deffile;
  106. string  dft_def_item;
  107. int     dft_defmenuwidth;
  108.  
  109.  
  110. /*****************************************************************************/
  111. /**** macro package initialization function ****/
  112. /*****************************************************************************/
  113. void _init(void)
  114. {
  115.   /* init DFT base with environment */
  116.   dft_base = trim(ltrim(inq_environment("DFTNBASE")));
  117.  
  118.   dxt_loc = "dxt.loc";          /* intermediate file for search results */
  119.   dft_loc = "dft.loc";          /* used for function menu */
  120.   dft_files = "dft_file.loc";   /* used for function file menu */
  121.   dft_xref = "dft_xref.loc";
  122.   dft_xref_item = "";
  123.   dft_deffile = "dft_def.loc";
  124.   dft_def_item = "";
  125.  
  126.   /* register macro to delete temporary files on exit from BRIEF */
  127.   register_macro(5, "_dxtmenu_exit");
  128. }
  129.  
  130. /*****************************************************************************/
  131. /* registered macro to perform actions on exit of BRIEF or */
  132. /* if changes of database names have happened */
  133. /*****************************************************************************/
  134. void _dxtmenu_exit(void)
  135. {
  136.   if (exist(dft_loc))
  137.     del(dft_loc);
  138.  
  139.   if (exist(dft_files))
  140.     del(dft_files);
  141.  
  142.   if (exist(dft_xref))
  143.     del(dft_xref);
  144.  
  145.   if (exist(dft_deffile))
  146.     del(dft_deffile);
  147. }
  148.  
  149. /*****************************************************************************/
  150. /**** user callable macros ****/
  151. /*****************************************************************************/
  152. void dft(void)                  /* find function */
  153. {
  154.   _dxt(DFTNPROG, dft_base);     /* do function retrieval */
  155. }
  156.  
  157. void dftfind(void)              /* find user defined item */
  158. {
  159.   string item;
  160.  
  161.   get_parm(NULL, item, "DFT function name: ", 50);
  162.   item = compress(trim(ltrim(item)));
  163.  
  164.   if (strlen(item))
  165.     _dxt_search(DFTNPROG, dft_base, item, 0, 0);
  166. }
  167.  
  168. void dftmenu(void)              /* build function menu */
  169. {
  170.   _dxtmenu(DFTNPROG, dft_base);
  171. }
  172.  
  173. void dftbase(void)              /* set DFT database name */
  174. {
  175.   get_parm(NULL, dft_base, "DFT database name: ", 50, dft_base);
  176.   dft_base = trim(ltrim(dft_base));
  177.   _dxtmenu_exit();              /* delete menu files */
  178. }
  179.  
  180. void dftfilemenu(void)          /* build DFT file menu */
  181. {
  182.   _dxtfilemenu(DFTNPROG, dft_base);
  183. }
  184.  
  185. void dftxrefmenu(void)          /* build function cross reference menu */
  186. {
  187.   _dxtxrefmenu(DFTNPROG, dft_base, 1);
  188. }
  189.  
  190. void dftxrefmenuagain(void)     /* rebuild menu for previous item */
  191. {
  192.   _dxtxrefmenu(DFTNPROG, dft_base, 0);
  193. }
  194.  
  195. void dftdefmenu(void)
  196. {
  197.   _dxtdefmenu(DFTNPROG, dft_base);
  198. }
  199.  
  200. /*****************************************************************************/
  201. /**** internal macro execution functions ****/
  202. /*****************************************************************************/
  203.  
  204. /*****************************************************************************/
  205. /* */
  206. /*****************************************************************************/
  207. void _exec_error(int retval, string format, string par1, string par2)
  208. {
  209.   if (retval >= 100)
  210.     message(format, par1, par2);
  211.   else 
  212.     message("Command execution error (%d)", retval);
  213. }
  214.  
  215. /*****************************************************************************/
  216. /* read search item from current buffer */
  217. /*****************************************************************************/
  218. string _extract_item(void)
  219. {
  220.   int    move_flag, markval, marklen;
  221.   int    start_line, start_col, end_line, end_col;
  222.   string itemname, act_char, tmp_char, fchar, nchar;
  223.  
  224.   fchar = "[_a-zA-Z]";         /* first character of an identifier */
  225.   nchar = "[_a-zA-Z0-9]";      /* not first character of an identifier */
  226.  
  227.   if (!(markval = inq_marked(start_line, start_col, end_line, end_col)))
  228.   {                             /* nothing marked, use cursor position */
  229.     if (!search_string(nchar, read(1)))
  230.     {
  231.       message("Invalid cursor position");
  232.       return "";
  233.     }
  234.  
  235.     save_position();            /* save the current position */
  236.     act_char = read(1);         /* read current character */
  237.  
  238.     whil